<template>
  <div>
    <el-card style="overflow:visible;">
      <el-form :model="form" size="mini" label-position="top" ref="form">
        <el-row :gutter="10">
          <el-col :lg="4" :md="6">
            <el-form-item label="机构" prop="BRANCHNO">
              <!-- <el-popover placement="bottom" width="200" trigger="click" v-model="popoverShow">
                <el-tree :data="treedata" :highlight-current="true" :expand-on-click-node="false" default-expand-all :props="defaultProps" @node-click="handleNodeClick">
                </el-tree>
                <el-input slot="reference" v-model="form.branchName" placeholder="请选择机构"></el-input>
              </el-popover> -->
              <select-tree :tree-data="treedata" :branch="form.branchName" @getBranchName="getBranch"></select-tree>
            </el-form-item>
          </el-col>
          <el-col :lg="4" :md="6">
            <el-form-item label="班次事件编号" prop="classId">
              <el-input v-model="form.classId" placeholder="请输入班次事件编号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="4" :md="6">
            <el-form-item label="班次事件名称" prop="className">
              <el-input v-model="form.className" placeholder="请输入班次事件名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :lg='2' :md='3' class="searchBtnMarginTop">
            <el-button type="primary" icon="el-icon-search" @click="classEventQuery" size='mini'>查询
            </el-button>
          </el-col>
          <el-col :lg="2" :md="3" class="searchBtnMarginTop">
            <el-button type="warning" size="mini" icon="el-icon-refresh" @click="resetForm('form')">重置</el-button>
          </el-col>
          <!-- <el-col :lg="2" :md="3" v-if="btnPermission('Button_User_Add')" class="searchBtnMarginTop">
            <el-button type="primary" size="mini" @click="createUser" icon='el-icon-plus'>新增用户</el-button>
          </el-col> -->
          <el-col :lg="2" :md="3" class="searchBtnMarginTop">
            <el-button type="primary" size="mini" @click="addDialog" icon="el-icon-plus">新增班次事件</el-button>
          </el-col>
        </el-row>
      </el-form>
      <el-row>
        <el-col>
          <el-table :data="tableData" style="margin-top:20px;">
            <el-table-column label="事件编号" prop="CLASSESEVENTID" width="130"></el-table-column>
            <el-table-column label="事件名称" prop="CLASSESEVENTNAME"></el-table-column>
            <el-table-column label="活动编号" prop="ACTIVITYTYPE"></el-table-column>
            <el-table-column label="活动类型" prop="ACTIVITYTYPENAME"></el-table-column>
            <el-table-column label="时长" prop="HOURS" align="center"></el-table-column>
            <el-table-column label="开始时间类型" align="center" prop="SRTTIMETYPE" width="160">
              <template slot-scope="scope">
                <span>{{scope.row.SRTTIMETYPE === "0"?"绝对时间":(scope.row.SRTTIMETYPE === "1"?"相对于班次开始时间后":(scope.row.SRTTIMETYPE === "2"?"相对于班次结束时间前":"任意时间"))}}</span>
              </template>
            </el-table-column>
            <el-table-column label="时间" prop="SRTTIME" width="120" align="center">
              <template slot-scope="scope">
                <div>
                  {{scope.row.SRTTIME}}
                  <span v-if="scope.row.ENDTIME != ''"> -- {{scope.row.ENDTIME}}</span>
                </div>
              </template>
            </el-table-column>
            <!-- <el-table-column label="结束时间" prop="ENDTIME" width="100" align="center"></el-table-column> -->
            <el-table-column label="是否带薪" prop="ISPAID" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.ISPAID === "1"?"是":"否"}}</span>
              </template>
            </el-table-column>
            <el-table-column label="最少次数" prop="MINTIMES" width="100" align="center"></el-table-column>
            <el-table-column label="最多次数" prop="MAXTIMES" width="100" align="center"></el-table-column>
            <el-table-column label="说明" prop="NOTES" width="120"></el-table-column>
            <el-table-column label="操作" fixed="right">
              <template slot-scope="scope">
                <el-tooltip class="item" effect="dark" content="修改" placement="top">
                  <el-button type="text" style="margin-left:0px" @click="editDialog(scope.row)">
                    <i class="el-icon-edit-outline"></i>
                  </el-button>
                </el-tooltip>
                <el-tooltip class="item" effect="dark" content="删除" placement="top">
                  <el-button type="text" style="margin-left:0px" @click="delEvent(scope.row)">
                    <i class="el-icon-delete"></i>
                  </el-button>
                </el-tooltip>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
        <el-col>
          <el-pagination style="text-align: right; margin-top:20px;" :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize" @size-change="handleInSizeChange" @current-change="handleInCurrentChange"
            :current-page="currpage" background layout="sizes, total, prev, pager, next, jumper" :total="tableTotal">
          </el-pagination>
        </el-col>
      </el-row>
      <!-- <el-row>
        <el-col>
          <el-pagination style="text-align: right; margin-top:20px;" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" @size-change="handleInSizeChange" @current-change="handleInCurrentChange" :current-page="currpage" background layout="sizes, total, prev, pager, next, jumper" :total="InTotalNum">
          </el-pagination>
        </el-col>
      </el-row> -->
    </el-card>
    <!-- 新增和编辑数据字典的Dialog -->
    <el-dialog :title="dialogTitle" v-if="editIsShow" :visible.sync="editIsShow" :close-on-click-modal="false"
      @close="closeDialog('ruleForm')" @open="openDialog">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" size="small">
        <el-row>
          <el-col :span="16">
            <el-form-item label="机构号" prop="branchName">
              <!-- <el-popover placement="bottom" width="200" trigger="click" v-model="popoverShow1">
                <el-tree :data="treedata" :highlight-current="true" :expand-on-click-node="false" default-expand-all :props="defaultProps" @node-click="handleNodeClick1">
                </el-tree>
                <el-input slot="reference" size="small" v-model="ruleForm.branchName" placeholder="请选择机构" :disabled="dialogTitle=='修改班次事件'"></el-input>
              </el-popover> -->
              <el-input v-model.trim="ruleForm.branchName" size="small" :disabled="dialogTitle=='修改班次事件'"
                v-if="dialogTitle=='修改班次事件'"></el-input>
              <select-tree :tree-data="treedata" :branch="ruleForm.branchName" @getBranchName="getBranch1"
                v-if="dialogTitle!='修改班次事件'"></select-tree>
            </el-form-item>
          </el-col>
          <el-col :span="16" v-if="ruleForm.CLASSESEVENTID">
            <el-form-item label="事件编号" prop="CLASSESEVENTID">
              <el-input v-model="ruleForm.CLASSESEVENTID" size="small" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="班次事件名称" prop="CLASSESEVENTNAME">
              <el-input v-model.trim="ruleForm.CLASSESEVENTNAME" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="13">
            <el-form-item label="活动类型" prop="ACTIVITYTYPE">
              <el-select v-model="ruleForm.ACTIVITYTYPE" size="small" placeholder="活动类型">
                <el-option v-for="item in actOptions" :key="item.ACTIVITYTYPE" :label="item.ACTIVITYTYPENAME"
                  :value="item.ACTIVITYTYPE"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="13">
            <el-form-item label="时长" prop="HOURS">
              <el-time-picker size="small" @focus="ChangeTime('HOURS')" v-model="ruleForm.HOURS" format="HH:mm"
                value-format="HH:mm" style="width: 100%" placeholder="请选择时长" @change="changeHour">
              </el-time-picker>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="开始时间类型" prop="SRTTIMETYPE">
              <el-radio-group v-model="ruleForm.SRTTIMETYPE" :disabled="ruleForm.HOURS==''">
                <el-col :span="13" style="margin-bottom:15px;">
                  <el-radio :label="'0'">绝对时间
                    <el-time-picker v-model="startTime0" @focus="ChangeTime('startTime0')" size="small"
                      style="width: 60%" format="HH:mm" value-format="HH:mm" :disabled="ruleForm.SRTTIMETYPE!='0'"
                      placeholder="开始时间">
                    </el-time-picker>
                    <el-time-picker v-model="endTime" size="small" @focus="ChangeTime('endTime')" style="width: 60%"
                     format="HH:mm" value-format="HH:mm" :disabled="ruleForm.SRTTIMETYPE!='0'"
                      placeholder="结束时间">
                    </el-time-picker>
                  </el-radio>
                </el-col>
                <el-col :span="13" style="margin-bottom:15px;">
                  <el-radio :label="'1'">相对于班次开始时间后
                    <el-time-picker v-model="startTime1" @focus="ChangeTime('startTime1')" size="small"
                      style="width: 60%" format="HH:mm" value-format="HH:mm" :disabled="ruleForm.SRTTIMETYPE!='1'"
                      placeholder="请选择时间">
                    </el-time-picker>
                  </el-radio>
                </el-col>
                <el-col :span="13" style="margin-bottom:15px;">
                  <el-radio :label="'2'">相对于班次结束时间前
                    <el-time-picker v-model="startTime2" @focus="ChangeTime('startTime2')" size="small"
                      style="width: 60%" format="HH:mm" value-format="HH:mm" :disabled="ruleForm.SRTTIMETYPE!='2'"
                      placeholder="请选择时间">
                    </el-time-picker>
                  </el-radio>
                </el-col>
                <el-col :span="13" style="margin-bottom:15px;">
                  <el-radio :label="'3'">任意时间</el-radio>
                </el-col>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="13">
            <el-form-item label="最早开始时间" prop="EARLIESTSRTTIME">
              <el-time-select v-model="ruleForm.EARLIESTSRTTIME" size="small" style="width: 100%" :picker-options="{
                  start: '00:00',
                  step: '0:30',
                  end: '24:00'
                }" format="HH:mm" value-format="HH:mm" placeholder="最早开始时间" :disabled="ruleForm.SRTTIMETYPE=='0'">
              </el-time-select>
            </el-form-item>
          </el-col> -->
          <!-- <el-col :span="13">
            <el-form-item label="最晚开始时间" prop="LATESTSRTTIME">
              <el-time-select v-model="ruleForm.LATESTSRTTIME" size="small" style="width: 100%" :picker-options="{
                  start: '00:00',
                  step: '0:30',
                  end: '24:00'
                }" format="HH:mm" value-format="HH:mm" placeholder="最晚开始时间" :disabled="ruleForm.SRTTIMETYPE=='0'">
              </el-time-select>
            </el-form-item>
          </el-col> -->
          <el-col :span="12">
            <el-form-item label="最少次数" prop="MINTIMES">
              <el-input-number v-model="ruleForm.MINTIMES" size="small" :min="0" :max="9"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="最多次数" prop="MAXTIMES">
              <el-input-number v-model="ruleForm.MAXTIMES" size="small" :min="0" :max="9"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否带薪">
              <el-switch v-model="ruleForm.ISPAID" active-value="1" inactive-value="0">
              </el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="说明" prop="NOTES">
              <el-input v-model.trim="ruleForm.NOTES" type="textarea" :rows="2" size="small"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11" :offset="13">
            <el-form-item>
              <el-button type="primary" size="small" @click="submitForm('ruleForm')">保存</el-button>
              <el-button size="small" type="danger" @click="resetForm('ruleForm')">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
  import request from "@/common/utils/requestWFM";
  import branchQuery from '@/message/wfm/baseData/branchManage/branchQuery'
  import getGlobalParams from "@/common/utils/getGlobalParams";
  import selectTree from "@/components/selectTree5/";
  import Query from '@/message/wfm/scheduleDataManage/classEventManage/classEventQuery'
  import Del from '@/message/wfm/scheduleDataManage/classEventManage/classEventDel'
  import Update from '@/message/wfm/scheduleDataManage/classEventManage/classEventUpdate'
  import Add from '@/message/wfm/scheduleDataManage/classEventManage/classEventAdd'
  import ActivityQuery from '@/message/wfm/scheduleDataManage/activityManage/actQuery'
  export default {
    components: {
      selectTree
    },
    mounted() {
      this.classEventQuery()
    },
    watch: {
      // 'ruleForm.SRTTIMETYPE':function(val){
      //   console.log(val)
      //   if(val == '0'){
      //     this.ruleForm.EARLIESTSRTTIME = '0:00'
      //     this.ruleForm.LATESTSRTTIME = '0:00'
      //   }
      // }
      // endTime(val) {
      //   // console.log('end',val)
      //   if (val == '00:00') {
      //     let time = parseInt(this.ruleForm.HOURS.split(':')[0]) * 60 * 60 + parseInt((this.ruleForm.HOURS.split(':')[
      //       1])) * 60
      //     time = 24 * 60 * 60 - time
      //     let hour = parseInt(time / 60 / 60) < 10 ? '0' + parseInt(time / 60 / 60) : parseInt(time / 60 / 60)
      //     let min = (time - parseInt(time / 60 / 60) * 60 * 60) / 60
      //     hour = hour < 10 ? '0' + hour : hour
      //     min = min < 10 ? '0' + min : min
      //     this.startTime0 = hour + ':' + min
      //   }
      // },
      // startTime0(val) {
      //   // console.log('start', val)
      //   if (val == '00:00') {
      //     this.endTime = this.ruleForm.HOURS
      //     return
      //   }
      // }
    },
    data() {
      return {
        ChangeTime(data) {
          var time = '00:00';
          var that = this;
          if (data == 'HOURS') {
            if (this.ruleForm.HOURS == '') {
              this.ruleForm.HOURS = time;
            }
          } else if (data == 'startTime0') {
            if (this.startTime0 == '') {
              this.startTime0 = time;
            }
          } else if (data == 'endTime') {
            if (this.endTime == '') {
              this.endTime = time;
            }
          } else if (data == 'startTime1') {
            if (this.startTime1 == '') {
              this.startTime1 = time;
            }
          } else if (data == 'startTime2') {
            if (this.startTime2 == '') {
              this.startTime2 = time;
            }
          }
        },
        defaultProps: {
          children: 'children',
          label: 'BRANCHNAME'
        },
        popoverShow: false,
        popoverShow1: false,
        resData: "",
        treedata: [],
        startTime0: '',
        startTime1: '',
        startTime2: '',
        endTime: '',
        actOptions: [], //活动类型
        tableTotal: 1,
        currpage: 1,
        pageSize: getGlobalParams.get("PageSize"),
        form: { //表单数据
          classId: "",
          className: "",
          branchNO: this.$store.getters.BranchNum,
          branchName: this.$store.getters.BranchName,
        },
        InTotalNum: 10,
        currpage: 1,
        pageSize: getGlobalParams.get("PageSize"),
        ruleForm: {
          branchName: '',
          branchNO: this.$store.getters.BranchNum,
          CLASSESEVENTID: '',
          CLASSESEVENTNAME: '',
          NOTES: '',
          ACTIVITYTYPE: '',
          HOURS: '',
          SRTTIMETYPE: '',
          SRTTIME: '',
          ENDTIME: '',
          ISPAID: '0',
          MINTIMES: '1',
          MAXTIMES: '1'
        },
        rules: {
          SRTTIMETYPE: [{
            required: true,
            message: '请选择开始时间类型',
            trigger: 'change'
          }],
          branchName: [{
            required: true,
            message: '请选择机构',
            trigger: 'change'
          }],
          CLASSESEVENTNAME: [{
              required: true,
              message: '请输入班次事件名称',
              trigger: 'blur'
            },
            {
              min: 1,
              max: 25,
              message: '长度在 1 到 25 个字符',
              trigger: 'blur'
            }
          ],
          HOURS: [{
            required: true,
            message: '请选择时长',
            trigger: 'change'
          }],
          ISPAID: [{
            required: true,
            message: '请选择是否带薪',
            trigger: 'change'
          }],
          ACTIVITYTYPE: [{
            required: true,
            message: '请选择活动类型',
            trigger: 'change'
          }],
          NOTES: [{
            min: 1,
            max: 250,
            message: '长度在 1 到 250 个字符',
            trigger: 'blur'
          }],
        },
        dialogTitle: '',
        editIsShow: false,
        input: '',
        select: '',
        tableData: [],
        FIELDNAME: ''
      }
    },
    methods: {
      getBranch(data) {
        // console.log(data)
        this.form.branchName = data.BRANCHNAME
        this.form.branchNO = data.BRANCHNO
        this.ruleForm.branchNO = data.BRANCHNO
        this.popoverShow = false
        // this.nodeclick = data.GroupName
        // this.queryGroupId = data.GroupId
        // if (!data.children) {
        //   this.quesTypeName = data.GroupName
        //   this.ruleForm.typeId = data.GroupId //获取到问题分类的groupId
        //   this.queryModel()
        //   this.popoverShow = false
        // } else if (data.GroupId == '1') {
        //   this.ruleForm.typeId = data.GroupId
        //   this.queryGroupId = ''
        //   this.nodeclick = ''
        //   this.quesTypeName = data.GroupName
        //   this.queryModel()
        // } else {
        //   this.nodeclick = ''
        // }

      },
      changeHour() {
        if (this.ruleForm.SRTTIMETYPE == '0') {
          this.startTime0 = ''
          this.endTime = ''
        }
      },
      // changeStartTime(val) {
      //   if (val == null) {
      //     this.endTime = ''
      //     return
      //   }
      //   if (val == '00:00') {
      //     this.endTime = this.ruleForm.HOURS
      //     return
      //   }
      //   if (val != '') {
      //     let start = parseInt(val.split(':')[0]) * 60 * 60 + parseInt(val.split(':')[1]) * 60
      //     let time = parseInt(this.ruleForm.HOURS.split(':')[0]) * 60 * 60 + parseInt((this.ruleForm.HOURS.split(':')[
      //       1])) * 60
      //     // let hour = parseInt(val.split(':')[0]) + parseInt(this.ruleForm.HOURS.split(':')[0])
      //     // let min = parseInt(val.split(':')[1]) + parseInt(this.ruleForm.HOURS.split(':')[1])
      //     let end = time + start
      //     let hour = parseInt(end / 60 / 60)
      //     let min = (end - hour * 60 * 60) / 60
      //     hour = hour >= 24 ? (hour - 24) : hour
      //     hour = hour < 10 ? '0' + hour : hour
      //     min = min < 10 ? '0' + min : min
      //     this.endTime = hour + ':' + min
      //   }
      // },
      // changeEndTime(val) {
      //   // if(val == '00:00'){
      //   //     this.startTime0 = this.ruleForm.fa-hourglass-start
      //   //     return 
      //   //   }
      //   if (this.endTime == null) {
      //     this.startTime0 = ''
      //     return
      //   }
      //   if (this.ruleForm.HOURS) {
      //     // if(this.startTime0){
      //     let end = parseInt(this.endTime.split(':')[0]) * 60 * 60 + parseInt(this.endTime.split(':')[1]) * 60
      //     let start = parseInt(this.ruleForm.HOURS.split(':')[0]) * 60 * 60 + parseInt(this.ruleForm.HOURS.split(':')[
      //       1]) * 60
      //     let time
      //     if (end < start) {
      //       time = end + 24 * 60 * 60 - start
      //     } else {
      //       time = end - start
      //     }
      //     let hour = parseInt(time / 60 / 60) < 10 ? '0' + parseInt(time / 60 / 60) : parseInt(time / 60 / 60)
      //     let min = (time - parseInt(time / 60 / 60) * 60 * 60) / 60
      //     hour = hour < 10 ? '0' + hour : hour
      //     min = min < 10 ? '0' + min : min
      //     this.startTime0 = hour + ':' + min
      //     // }else{
      //     //   // this.startTime0 = this.endTime - this.ruleForm.HOURS
      //     // }
      //   }

      // },
      getBranch1(data) {
        // console.log(data)
        this.ruleForm.branchName = data.BRANCHNAME
        this.ruleForm.branchNO = data.BRANCHNO
        this.popoverShow1 = false
        // this.nodeclick = data.GroupName
        // this.queryGroupId = data.GroupId
        // if (!data.children) {
        //   this.quesTypeName = data.GroupName
        //   this.ruleForm.typeId = data.GroupId //获取到问题分类的groupId
        //   this.queryModel()
        //   this.popoverShow = false
        // } else if (data.GroupId == '1') {
        //   this.ruleForm.typeId = data.GroupId
        //   this.queryGroupId = ''
        //   this.nodeclick = ''
        //   this.quesTypeName = data.GroupName
        //   this.queryModel()
        // } else {
        //   this.nodeclick = ''
        // }

      },
      // 活动查询
      async actQuery() {
        let resBody = new ActivityQuery()
        resBody.data.CurrPage = 1;
        resBody.data.PageRowNum = 20;
        resBody.data.ACTIVITYCATEG = '02';
        let response = await request(resBody);
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.actOptions = response.BODY.RSPSTRUCT
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          })
        }
      },
      //前端分页
      handleInCurrentChange(val) {
        this.currpage = val;
        // console.log(`当前页: ${val}`);
      },
      handleInSizeChange(val) {
        this.pageSize = val;
        this.classEventQuery();
      },
      // 班次事件查询
      async classEventQuery() {
        let resBody = new Query()
        resBody.data.BRANCHNO = this.form.branchNO
        resBody.data.CLASSESEVENTID = this.form.classId
        resBody.data.CLASSESEVENTNAME = this.form.className
        resBody.data.CurrPage = this.currpage;
        resBody.data.PageRowNum = this.pageSize;
        let response = await request(resBody);
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.tableData = response.BODY.RSPSTRUCT
          this.tableTotal = response.BODY.TotalRowNum;
          this.form.branchName = response.BODY.BRANCHNAME
          this.form.branchNO = response.BODY.BRANCHNO
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          })
        }
      },
      // 班次事件删除
      delEvent(row) {
        this.$confirm('此操作将删除该班次事件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          let resBody = new Del()
          resBody.data.CLASSESEVENTID = row.CLASSESEVENTID
          let response = await request(resBody);
          if (response.SYS_HEAD.ReturnCode == "000000") {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.classEventQuery()
          } else {
            this.$message({
              type: "error",
              message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
            })
          }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        })
      },
      // //前端分页
      // handleInCurrentChange(val) {
      //   this.currpage = val;
      //   this.stopWordQuery();
      //   // console.log(`当前页: ${val}`);
      // },
      // handleInSizeChange(val) {
      //   this.pageSize = val;
      //   this.stopWordQuery();
      // },
      addDialog() {
        this.editIsShow = true
        this.dialogTitle = '新增班次事件'
        this.actQuery()
        this.ruleForm.branchName = ''
        this.ruleForm.branchNO = ''
        this.ruleForm.CLASSESEVENTID = ''
        this.ruleForm.CLASSESEVENTNAME = ''
        this.ruleForm.NOTES = ''
        this.ruleForm.ACTIVITYTYPE = ''
        this.ruleForm.HOURS = ''
        this.ruleForm.SRTTIMETYPE = ''
        this.ruleForm.SRTTIME = ''
        this.ruleForm.ENDTIME = ''
        this.ruleForm.ISPAID = ''
        this.startTime0 = ''
        this.startTime1 = ''
        this.startTime2 = ''
        this.endTime = ''
        this.ruleForm.MINTIMES = '1'
        this.ruleForm.MAXTIMES = '1'
      },
      editDialog(row) {
        console.log(row)
        this.editIsShow = true
        this.dialogTitle = '修改班次事件'
        this.ruleForm = JSON.parse(JSON.stringify(row))
        this.ruleForm.branchNO = this.form.branchNO
        this.ruleForm.branchName = this.form.branchName
        if (this.ruleForm.SRTTIMETYPE == '0') {
          this.startTime0 = this.ruleForm.SRTTIME
          this.endTime = this.ruleForm.ENDTIME
        } else if (this.ruleForm.SRTTIMETYPE == '1') {
          this.startTime1 = this.ruleForm.SRTTIME
        } else if (this.ruleForm.SRTTIMETYPE == '2') {
          this.startTime2 = this.ruleForm.SRTTIME
        }
        this.actQuery()
      },
      submitForm(formName) {
        this.$refs[formName].validate(async (valid) => {
          if (valid) {
            if (this.ruleForm.MINTIMES > this.ruleForm.MAXTIMES) {
              this.$message({
                type: "error",
                message: '最多次数不能小于最少次数'
              })
              return false
            }
            if (this.dialogTitle == '修改班次事件') {
              let resBody = new Update()
              resBody.data = JSON.parse(JSON.stringify(this.ruleForm))
              if (this.ruleForm.SRTTIMETYPE == '0') {
                resBody.data.SRTTIME = this.startTime0
                resBody.data.ENDTIME = this.endTime
              } else if (this.ruleForm.SRTTIMETYPE == '1') {
                resBody.data.SRTTIME = this.startTime1
                resBody.data.ENDTIME = ''
              } else if (this.ruleForm.SRTTIMETYPE == '2') {
                resBody.data.SRTTIME = this.startTime2
                resBody.data.ENDTIME = ''
              } else if (this.ruleForm.SRTTIMETYPE == '3') {
                resBody.data.SRTTIME = ''
                resBody.data.ENDTIME = ''
              }
              // resBody.data.CLASSESEVENTID = this.ruleForm.CLASSESEVENTID
              // resBody.data.CLASSESEVENTNAME = this.ruleForm.CLASSESEVENTNAME
              // resBody.data.NOTES = this.ruleForm.NOTES
              // resBody.data.ACTIVITYTYPE = this.ruleForm.ACTIVITYTYPE
              // resBody.data.HOURS = this.ruleForm.HOURS
              // resBody.data.SRTTIMETYPE = this.ruleForm.SRTTIMETYPE
              // resBody.data.EARLIESTSRTTIME = this.ruleForm.EARLIESTSRTTIME
              // resBody.data.LATESTSRTTIME = this.ruleForm.LATESTSRTTIME
              // resBody.data.ISPAID = this.ruleForm.ISPAID == true ? '1':'0'
              let response = await request(resBody);
              if (response.SYS_HEAD.ReturnCode == "000000") {
                this.editIsShow = false
                this.classEventQuery()
                this.closeDialog(formName)
              } else {
                this.$message({
                  type: "error",
                  message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD
                    .ReturnMessage
                })
              }
            } else {
              let resBody = new Add()
              resBody.data = JSON.parse(JSON.stringify(this.ruleForm))
              resBody.data.BRANCHNO = this.ruleForm.branchNO
              if (this.ruleForm.SRTTIMETYPE == '0') {
                resBody.data.SRTTIME = this.startTime0
                resBody.data.ENDTIME = this.endTime
              } else if (this.ruleForm.SRTTIMETYPE == '1') {
                resBody.data.SRTTIME = this.startTime1
                resBody.data.ENDTIME = ''
              } else if (this.ruleForm.SRTTIMETYPE == '2') {
                resBody.data.SRTTIME = this.startTime2
                resBody.data.ENDTIME = ''
              } else if (this.ruleForm.SRTTIMETYPE == '3') {
                resBody.data.SRTTIME = ''
                resBody.data.ENDTIME = ''
              }
              let response = await request(resBody);
              if (response.SYS_HEAD.ReturnCode == "000000") {
                this.editIsShow = false
                this.$refs[formName].resetFields();
                this.$refs[formName].clearValidate();
                this.ruleForm.SRTTIMETYPE = ''
                this.ruleForm.SRTTIME = ''
                this.ruleForm.ENDTIME = ''
                this.ruleForm.ISPAID = ''
                this.startTime0 = ''
                this.startTime1 = ''
                this.startTime2 = ''
                this.endTime = ''
                this.ruleForm.MINTIMES = '1'
                this.ruleForm.MAXTIMES = '1'
                this.classEventQuery()
              } else {
                this.$message({
                  type: "error",
                  message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD
                    .ReturnMessage
                })
              }
            }
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        if(this.$refs[formName] != undefined){
          this.$refs[formName].clearValidate();
          this.$refs[formName].resetFields()
        }
      },
      openDialog() {
        if (this.$refs['ruleForm'] != undefined) {
          this.$refs['ruleForm'].clearValidate();
          this.$refs['ruleForm'].resetFields();
        }
      },
      closeDialog(formName) {
        this.$refs[formName].resetFields();
        this.$refs[formName].clearValidate();
        this.ruleForm.branchName = ''
        this.ruleForm.branchNO = ''
        this.ruleForm.CLASSESEVENTID = ''
        this.ruleForm.CLASSESEVENTNAME = ''
        this.ruleForm.NOTES = ''
        this.ruleForm.ACTIVITYTYPE = ''
        this.ruleForm.HOURS = ''
        this.ruleForm.SRTTIMETYPE = ''
        this.ruleForm.SRTTIME = ''
        this.ruleForm.ENDTIME = ''
        this.ruleForm.ISPAID = ''
        this.startTime0 = ''
        this.startTime1 = ''
        this.startTime2 = ''
        this.endTime = ''
        this.ruleForm.MINTIMES = '1'
        this.ruleForm.MAXTIMES = '1'
      },
    }
  }

</script>
